<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>资源中心 - AI智能教学培训系统</title>
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
    <script src="https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.js"></script>
    <script src="https://unpkg.com/element-ui/lib/index.js"></script>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Segoe UI', 'Microsoft YaHei', sans-serif;
        }

        :root {
            --primary: #4361ee;
            --secondary: #3f37c9;
            --accent: #4895ef;
            --light: #f8f9fa;
            --dark: #212529;
            --success: #4cc9f0;
            --warning: #f72585;
            --gray: #6c757d;
        }

        body {
            background-color: #f5f7fb;
            color: var(--dark);
        }

        .app-container {
            display: flex;
            min-height: 100vh;
        }

        /* 侧边栏样式 */
        .sidebar {
            width: 260px;
            background: linear-gradient(180deg, var(--primary), var(--secondary));
            color: white;
            box-shadow: 3px 0 10px rgba(0, 0, 0, 0.1);
            transition: all 0.3s;
            position: fixed;
            height: 100vh;
            overflow-y: auto;
        }

        .logo-container {
            padding: 20px;
            text-align: center;
            border-bottom: 1px solid rgba(255, 255, 255, 0.1);
        }

        .logo {
            font-size: 24px;
            font-weight: 700;
            display: flex;
            align-items: center;
            justify-content: center;
        }

        .logo-icon {
            margin-right: 10px;
            font-size: 28px;
        }

        .nav-menu {
            padding: 20px 0;
        }

        .nav-item {
            padding: 12px 25px;
            display: flex;
            align-items: center;
            cursor: pointer;
            transition: all 0.3s;
            border-left: 4px solid transparent;
        }

        .nav-item:hover {
            background: rgba(255, 255, 255, 0.1);
            border-left: 4px solid var(--accent);
        }

        .nav-item.active {
            background: rgba(255, 255, 255, 0.1);
            border-left: 4px solid var(--accent);
        }

        /* 侧边栏链接无下划线且不变色 */
        a.nav-item {
            text-decoration: none;
            color: inherit;
        }
        a.nav-item:visited,
        a.nav-item:active,
        a.nav-item:focus {
            color: inherit;
        }

        .nav-icon {
            margin-right: 12px;
            font-size: 18px;
        }

        /* 主内容区 */
        .main-content {
            flex: 1;
            margin-left: 260px;
            padding: 30px;
            transition: all 0.3s;
        }

        .header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 30px;
        }

        .page-title {
            font-size: 28px;
            font-weight: 600;
            color: var(--dark);
        }

        .user-info {
            display: flex;
            align-items: center;
        }

        .avatar {
            width: 40px;
            height: 40px;
            border-radius: 50%;
            background: var(--accent);
            display: flex;
            align-items: center;
            justify-content: center;
            color: white;
            font-weight: bold;
            margin-right: 10px;
        }

        /* 资源中心特定样式 */
        .resource-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 25px;
        }

        .search-input {
            width: 300px;
        }

        .resource-tabs {
            display: flex;
            background: #f0f2f5;
            border-radius: 8px;
            padding: 5px;
        }

        .resource-tab {
            padding: 8px 20px;
            border-radius: 6px;
            cursor: pointer;
            font-size: 14px;
            transition: all 0.3s;
        }

        .resource-tab.active {
            background: white;
            box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
            font-weight: 500;
            color: var(--primary);
        }

        .resource-grid {
            display: grid;
            grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
            gap: 20px;
            margin-bottom: 30px;
        }

        .resource-card {
            background: white;
            border-radius: 12px;
            overflow: hidden;
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
            transition: all 0.3s;
        }

        .resource-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 8px 20px rgba(0, 0, 0, 0.1);
        }

        .resource-image {
            height: 160px;
            background: linear-gradient(135deg, var(--primary), var(--accent));
            position: relative;
            display: flex;
            align-items: center;
            justify-content: center;
            color: white;
            font-size: 48px;
        }

        .resource-type {
            position: absolute;
            top: 15px;
            right: 15px;
            background: white;
            color: var(--primary);
            padding: 4px 10px;
            border-radius: 20px;
            font-size: 12px;
            font-weight: 500;
        }

        .resource-body {
            padding: 20px;
        }

        .resource-title {
            font-size: 18px;
            font-weight: 600;
            margin-bottom: 10px;
            display: -webkit-box;
            -webkit-line-clamp: 2;
            -webkit-box-orient: vertical;
            overflow: hidden;
            height: 50px;
        }

        .resource-meta {
            display: flex;
            justify-content: space-between;
            color: var(--gray);
            font-size: 14px;
            margin-bottom: 15px;
        }

        .resource-description {
            color: var(--gray);
            margin-bottom: 15px;
            display: -webkit-box;
            -webkit-line-clamp: 3;
            -webkit-box-orient: vertical;
            overflow: hidden;
            height: 60px;
        }

        .resource-actions {
            display: flex;
            justify-content: space-between;
        }

        .resource-btn {
            flex: 1;
            padding: 10px;
            border: none;
            background: #f8f9fa;
            color: var(--dark);
            cursor: pointer;
            transition: all 0.3s;
            font-size: 14px;
            display: flex;
            align-items: center;
            justify-content: center;
        }

        .resource-btn:first-child {
            border-radius: 6px 0 0 6px;
            border-right: 1px solid #eee;
        }

        .resource-btn:last-child {
            border-radius: 0 6px 6px 0;
        }

        .resource-btn:hover {
            background: #e9ecef;
        }

        .resource-btn.primary {
            background: var(--primary);
            color: white;
        }

        .resource-btn.primary:hover {
            background: var(--secondary);
        }

        .resource-icon {
            margin-right: 6px;
        }

        .recommend-section {
            margin-top: 40px;
        }

        .section-title {
            font-size: 20px;
            font-weight: 600;
            margin-bottom: 20px;
            position: relative;
            padding-left: 15px;
        }

        .section-title:before {
            content: '';
            position: absolute;
            left: 0;
            top: 5px;
            height: 20px;
            width: 5px;
            background: var(--primary);
            border-radius: 3px;
        }

        .empty-state {
            text-align: center;
            padding: 50px 20px;
            grid-column: 1 / -1;
        }

        .empty-icon {
            font-size: 60px;
            color: #dee2e6;
            margin-bottom: 20px;
        }

        .empty-text {
            font-size: 18px;
            color: var(--gray);
            margin-bottom: 20px;
        }

        /* 响应式设计 */
        @media (max-width: 992px) {
            .sidebar {
                width: 70px;
            }

            .logo-text, .nav-text {
                display: none;
            }

            .logo-icon {
                margin-right: 0;
            }

            .nav-item {
                justify-content: center;
            }

            .nav-icon {
                margin-right: 0;
            }

            .main-content {
                margin-left: 70px;
            }

            .resource-header {
                flex-direction: column;
                align-items: flex-start;
                gap: 15px;
            }

            .search-input {
                width: 100%;
            }
        }

        @media (max-width: 768px) {
            .resource-grid {
                grid-template-columns: 1fr;
            }
        }

        /* 动画效果 */
        @keyframes fadeIn {
            from { opacity: 0; transform: translateY(10px); }
            to { opacity: 1; transform: translateY(0); }
        }

        .fade-in {
            animation: fadeIn 0.5s ease forwards;
        }

        /* 文件类型图标颜色 */
        .file-type-pdf { color: #e74c3c; }
        .file-type-video { color: #3498db; }
        .file-type-doc { color: #2ecc71; }
        .file-type-zip { color: #f39c12; }
        .file-type-ppt { color: #e67e22; }
    </style>
</head>
<body>
<div id="app">
    <div class="app-container">
        <!-- 侧边导航 -->
        <div id="sidebar"></div>

        <!-- 主内容区 -->
        <div class="main-content">
            <!-- 顶部导航 -->
            <div class="header">
                <h1 class="page-title">资源中心</h1>
                <div class="user-info">
                    <div class="avatar">张</div>
                    <div>
                        <div class="user-name">张明</div>
                        <div class="user-role">学生</div>
                    </div>
                </div>
            </div>

            <!-- 资源头部区域 -->
            <div class="resource-header">
                <el-input
                        placeholder="搜索资源名称或关键词"
                        prefix-icon="el-icon-search"
                        v-model="searchQuery"
                        class="search-input">
                </el-input>

                <div class="resource-tabs">
                    <div
                            class="resource-tab"
                            :class="{active: activeTab === 'all'}"
                            @click="activeTab = 'all'">
                        全部资源
                    </div>
                    <div
                            class="resource-tab"
                            :class="{active: activeTab === 'course'}"
                            @click="activeTab = 'course'">
                        课程资料
                    </div>
                    <div
                            class="resource-tab"
                            :class="{active: activeTab === 'video'}"
                            @click="activeTab = 'video'">
                        视频课程
                    </div>
                    <div
                            class="resource-tab"
                            :class="{active: activeTab === 'exercise'}"
                            @click="activeTab = 'exercise'">
                        习题库
                    </div>
                    <div
                            class="resource-tab"
                            :class="{active: activeTab === 'other'}"
                            @click="activeTab = 'other'">
                        其他
                    </div>
                </div>
            </div>

            <!-- 资源列表 -->
            <div class="resource-grid">
                <template v-if="filteredResources.length > 0">
                    <div
                            class="resource-card fade-in"
                            v-for="(resource, index) in filteredResources"
                            :key="index">
                        <div class="resource-image">
                            <i :class="getFileIcon(resource.type)"></i>
                            <div class="resource-type">{{ resource.type }}</div>
                        </div>
                        <div class="resource-body">
                            <h3 class="resource-title">{{ resource.title }}</h3>
                            <div class="resource-meta">
                                <span><i class="el-icon-time"></i> {{ resource.date }}</span>
                            </div>
                            <p class="resource-description">{{ resource.description }}</p>
                            <div class="resource-actions">
                                <button class="resource-btn" @click="viewResource(resource)">
                                    <i class="el-icon-view resource-icon"></i>
                                    预览
                                </button>
                                <button class="resource-btn primary" @click="downloadResource(resource)">
                                    <i class="el-icon-download resource-icon"></i>
                                    下载
                                </button>
                            </div>
                        </div>
                    </div>
                </template>

                <div class="empty-state" v-else>
                    <i class="el-icon-folder-opened empty-icon"></i>
                    <div class="empty-text">没有找到相关资源</div>
                    <el-button type="primary" @click="resetFilters">重置筛选条件</el-button>
                </div>
            </div>

            <!-- 推荐资源 -->
            <div class="recommend-section">
                <div class="resource-grid">
                    <div
                            class="resource-card fade-in"
                            v-for="(resource, index) in recommendedResources"
                            :key="'rec-'+index">
                        <div class="resource-image" :style="{background: resource.color}">
                            <i :class="getFileIcon(resource.type)"></i>
                            <div class="resource-type">{{ resource.type }}</div>
                        </div>
                        <div class="resource-body">
                            <h3 class="resource-title">{{ resource.title }}</h3>
                            <div class="resource-meta">
                                <span><i class="el-icon-time"></i> {{ resource.date }}</span>
                            </div>
                            <p class="resource-description">{{ resource.description }}</p>
                            <div class="resource-actions">
                                <button class="resource-btn" @click="viewResource(resource)">
                                    <i class="el-icon-view resource-icon"></i>
                                    预览
                                </button>
                                <button class="resource-btn primary" @click="downloadResource(resource)">
                                    <i class="el-icon-download resource-icon"></i>
                                    下载
                                </button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script>
    new Vue({
        el: '#app',
        data: {
            searchQuery: '',
            activeTab: 'all',
            resources: [], // 改为由API获取
            recommendedResources: []
        },
        mounted() {
            fetch('/resources', {
                headers: {
                    'Authorization': 'Bearer ' + localStorage.getItem('token')
                }
            })
            .then(res => res.json())
            .then(resp => {
                if (resp.success && Array.isArray(resp.data)) {
                    // 为API数据添加样式属性，保持原有的美观效果
                    this.resources = resp.data.map((resource, index) => ({
                        ...resource,
                        // 添加渐变色背景
                        color: this.getResourceColor(index),
                        // 确保类型字段存在
                        type: resource.type || 'PDF',
                        // 确保上传者字段存在
                        //uploader: resource.uploader || '未知',
                        // 确保日期字段存在
                        date: resource.date || new Date().toISOString().split('T')[0],
                        // 确保描述字段存在
                        description: resource.description || '暂无描述',
                        // 确保课程字段存在
                        course: resource.course || '通用'
                    }));
                } else {
                    console.error('获取资源数据失败:', resp.message);
                    this.resources = [];
                }
            })
            .catch(error => {
                console.error('请求资源数据出错:', error);
                this.resources = [];
            });
        },
        computed: {
            filteredResources() {
                let filtered = this.resources;

                // 根据搜索查询过滤
                if (this.searchQuery) {
                    const query = this.searchQuery.toLowerCase();
                    filtered = filtered.filter(resource =>
                        resource.title.toLowerCase().includes(query) ||
                        resource.description.toLowerCase().includes(query) ||
                        resource.course.toLowerCase().includes(query)
                    );
                }

                // 根据活动标签过滤
                switch (this.activeTab) {
                    case 'course':
                        filtered = filtered.filter(resource =>
                            resource.type === 'PDF' || resource.type === 'DOC' || resource.type === 'PPT'
                        );
                        break;
                    case 'video':
                        filtered = filtered.filter(resource =>
                            resource.type === '视频'
                        );
                        break;
                    case 'exercise':
                        filtered = filtered.filter(resource =>
                            resource.type === '习题'
                        );
                        break;
                    case 'other':
                        filtered = filtered.filter(resource =>
                            resource.type === 'ZIP' || resource.type === '其他'
                        );
                        break;
                    default:
                        // 'all' 不进行过滤
                        break;
                }

                return filtered;
            }
        },
        methods: {
            getFileIcon(type) {
                const icons = {
                    'PDF': 'el-icon-document file-type-pdf',
                    '视频': 'el-icon-video-camera file-type-video',
                    '习题': 'el-icon-s-claim file-type-doc',
                    'DOC': 'el-icon-document file-type-doc',
                    'ZIP': 'el-icon-folder file-type-zip',
                    'PPT': 'el-icon-data-board file-type-ppt',
                    '其他': 'el-icon-files'
                };
                return icons[type] || 'el-icon-document';
            },
            viewResource(resource) {
                this.$message(`预览资源: ${resource.title}`);
                // 实际应用中这里会打开资源预览
            },
            downloadResource(resource) {
                this.$message.success(`开始下载: ${resource.title}`);
                // 实际应用中这里会触发下载
            },
            resetFilters() {
                this.searchQuery = '';
                this.activeTab = 'all';
            },
            // 根据索引生成资源颜色
            getResourceColor(index) {
                const colors = [
                    'linear-gradient(135deg, #4361ee, #3f37c9)',
                    'linear-gradient(135deg, #4895ef, #3f37c9)',
                    'linear-gradient(135deg, #f72585, #4895ef)',
                    'linear-gradient(135deg, #2ec4b6, #e71d36)',
                    'linear-gradient(135deg, #f8961e, #4895ef)',
                    'linear-gradient(135deg, #7209b7, #4361ee)',
                    'linear-gradient(135deg, #4cc9f0, #4895ef)'
                ];
                return colors[index % colors.length];
            }
        }
    });
</script>
<script>
  fetch('sidebar.html').then(r=>r.text()).then(html=>{document.getElementById('sidebar').innerHTML=html;});
</script>
</body>
</html>